using System;
using System.ComponentModel;
using EzDesk.DesktopClient.Model;
using EzDesk.DesktopClient.MVVMEnhance;
using EzDesk.DesktopClient.UtilityView.ViewContract;
using EzDesk.MVVMBase;

namespace EzDesk.DesktopClient.UtilityView.ViewModel
{
    public interface IFeedItemViewModel : IViewModel, INotifyPropertyChanged, IDisposable
    {
        Feed FeedModel { get; set; }

        string ContentTitle { get; set; }
        string ContentBody { get; set; }
        DateTime LastUpdate { get; set; }

        bool IsRead { get; set; }

        bool IsAvailable { get; set; }

        bool IsMark { get; set; }

        string IconUrl { get; set; }
    }

    public interface IFeedItemViewModel<out TFeedItemView> : IFeedItemViewModel
    {
        IFeedItemViewModel<TFeedItemView> SetModel(Feed feed);
        TFeedItemView View { get; }
    }

    public class FeedItemViewModel<TFeedItemView,TFeedItemViewModel> :
        ViewModelWithSingleContainer<TFeedItemView>, IFeedItemViewModel<TFeedItemView>
        where TFeedItemView : IFeedItemView<TFeedItemViewModel>
        where TFeedItemViewModel : IFeedItemViewModel<TFeedItemView>
    {
        public IFeedItemViewModel<TFeedItemView> SetModel(Feed feed)
        {
            this.FeedModel = feed;
            return this;
        }

        public Feed _feedModel;

        public Feed FeedModel
        {
            get { return _feedModel; }
            set { _feedModel = value; RaisePropertyChanged("FeedModel"); }
        }

        public string ContentTitle
        {
            get { return FeedModel.TransformedTitle; }
            set
            {
                FeedModel.TransformedBody = value;
                RaisePropertyChanged("ContentTitle");
            }
        }

        public string ContentBody
        {
            get { return FeedModel.TransformedBody; }
            set
            {
                FeedModel.TransformedBody = value;
                RaisePropertyChanged("ContentBody");
            }
        }

        public DateTime LastUpdate
        {
            get { return FeedModel.UpdateOn.Value; }
            set
            {
                FeedModel.UpdateOn = value;
                RaisePropertyChanged("LastUpdate");
            }
        }

        public bool IsRead
        {
            get { return FeedModel.IsRead.Value; }
            set
            {
                FeedModel.IsRead = value;
                RaisePropertyChanged("IsRead");
            }
        }

        public bool IsAvailable
        {
            get { return FeedModel.IsAvailable.Value; }
            set
            {
                FeedModel.IsAvailable = value;
                RaisePropertyChanged("IsAvailable");
            }
        }

        public bool IsMark
        {
            get { return FeedModel.IsMark.Value; }
            set
            {
                FeedModel.IsMark = value;
                RaisePropertyChanged("IsMark");
            }
        }

        public string IconUrl
        {
            get { return FeedModel.IconUrl; }
            set
            {
                FeedModel.IconUrl = value;
                RaisePropertyChanged("IconUrl");
            }
        }
    }
}
